<html>
<head>
<link rel="help" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#dom-document-dir"/>
<script>
var headReadDocumentDir = document.dir;
document.dir = "rtl";
var headWriteDocumentDir = document.dir;
</script>
</head>
<body>
<script src="../../resources/js-test.js"></script>
<script>
description("document.dir should reflect the 'dir' content attribute of the &lt;html&gt; element and should be settable in &lt;head&gt;.");

debug("Read document.dir in head");
shouldBeEqualToString("headReadDocumentDir", "");
debug("");

debug("Write document.dir in head");
shouldBeEqualToString("headWriteDocumentDir", "rtl");
debug("");

debug("Read document.dir in body");
shouldBeEqualToString("document.dir", "rtl");
debug("");

debug("Read document.documentElement.dir in body");
shouldBeEqualToString("document.documentElement.dir", "rtl");
debug("");

debug("Read document.documentElement.getAttribute('dir') in body");
shouldBeEqualToString("document.documentElement.getAttribute('dir')", "rtl");
debug("");

debug("Read document.body.dir in body");
shouldBeEqualToString("document.body.dir", "");
debug("");

debug("Write document.dir in body");
document.dir = "ltr";
shouldBeEqualToString("document.dir", "ltr");
debug("");

debug("Read document.documentElement.dir in body");
shouldBeEqualToString("document.documentElement.dir", "ltr");
debug("");

debug("Read document.body.dir in body");
shouldBeEqualToString("document.body.dir", "");
debug("");

debug("Read document.documentElement.getAttribute('dir') in body");
shouldBeEqualToString("document.documentElement.getAttribute('dir')", "ltr");
debug("");

debug("Write non-canonical case document.dir in body");
shouldNotThrow("document.dir = 'RTL'");
shouldBeEqualToString("document.dir", "rtl");
debug("");

debug("Read document.documentElement.getAttribute('dir') in body");
shouldBeEqualToString("document.documentElement.getAttribute('dir')", "RTL");
debug("");

debug("Write invalid document.dir in body");
shouldNotThrow("document.dir = 'WRONG'");
shouldBeEqualToString("document.dir", "");
debug("");

debug("Read document.documentElement.getAttribute('dir') in body");
shouldBeEqualToString("document.documentElement.getAttribute('dir')", "WRONG");
debug("");

debug("Write non-canonical case document.body.dir in body");
shouldNotThrow("document.body.dir = 'RTL'");
shouldBeEqualToString("document.body.dir", "rtl");
debug("");

debug("Write invalid document.body.dir in body");
shouldNotThrow("document.body.dir = 'WRONG'");
shouldBeEqualToString("document.body.dir", "");
debug("");

document.dir = null;
debug("Read document.dir in body");
shouldBeEqualToString("document.dir", "");
debug("");

debug("Read document.documentElement.getAttribute('dir') in body");
shouldBeEqualToString("document.documentElement.getAttribute('dir')", "null");
debug("");

</script>
</body>
</html>
